﻿// (c) Copyright Michael Antonio.
// This source is subject to the Microsoft Public License (Ms-PL).
// Please see http://go.microsoft.com/fwlink/?LinkID=131993 for details.
// All other rights reserved
using System;
using System.Collections.Generic;
using MichMan.Utilities;

namespace Subsonic.Data
{
    public enum ResponseStatus
    {
        Failed,
        Ok,
    }

    public enum AlbumListType { random, newest, highest, frequent, recent }

    public enum JukeboxAction { get, start, stop, skip, add, clear, remove, shuffle, setGain }

    [ZPath("subsonic-response")]
    public class SubsonicResponse
    {
        [ZPath("musicFolders")]
        public MusicFolders MusicFolders { get; set; }
        [ZPath("indexes")]
        public Indexes Indexes { get; set; }
        [ZPath("directory")]
        public Directory Directory { get; set; }
        [ZPath("nowPlaying")]
        public NowPlaying NowPlaying { get; set; }
        [ZPath("searchResult")]
        public SearchResult SearchResult { get; set; }
        [ZPath("playlists")]
        public Playlists Playlists { get; set; }
        [ZPath("playlist")]
        public Playlist Playlist { get; set; }
        [ZPath("jukeboxPlaylist")] 
        public JukeboxPlaylist JukeboxPlaylist { get; set; }
        [ZPath("license")]
        public License License { get; set; }
        [ZPath("chatMessages")] 
        public ChatMessages ChatMessages { get; set; }
        [ZPath("albumList")]
        public AlbumList AlbumList { get; set; }
        [ZPath("randomSongs")]
        public RandomSongs RandomSongs { get; set; }
        [ZPath("lyrics")]
        public Lyrics Lyrics { get; set; }
        [ZPath("error")]
        public Error Error { get; set; }

        [ZPath("@status")]
        public ResponseStatus Status { get; set; }
        [ZPath("@version")]
        public string Version { get; set; }
    }

    public class License
    {
        [ZPath("@valid")]
        public bool Valid { get; set; }
        [ZPath("@email")]
        public string EMail { get; set; }
        [ZPath("@key")]
        public string Key { get; set; }
        [ZPath("@date")]
        public DateTime Date { get; set; }
    }

    public class Error
    {
        [ZPath("@code")]
        public int Code { get; set; }
        [ZPath("@message")]
        public string Message { get; set; }
    }

    public class MusicFolder
    {
        [ZPath("@id")]
        public string Id { get; set; }
        [ZPath("@name")]
        public string Name { get; set; }
    }

    [ZPath("musicFolder")]
    public class MusicFolders : List<MusicFolder>
    {
    }

    public class Indexes
    {
        [ZPath("shortcut")]
        public List<Artist> Shortcuts { get; set; }
        [ZPath("index")]
        public List<Index> Indecies { get; set; }
        [ZPath("@lastModified")]
        public long LastModified { get; set; }
    }

    public class Index
    {
        [ZPath("artist")]
        public List<Artist> Artist { get; set; }
        [ZPath("@name")]
        public string Name { get; set; }
    }

    public class Artist
    {
        [ZPath("@id")]
        public string Id { get; set; }
        [ZPath("@name")]
        public string Name { get; set; }
    }

    [ZPath("album")]
    public class AlbumList : List<Child>
    {
    }

    [ZPath("song")]
    public class RandomSongs: List<Child>
    {
    }

    public class Lyrics
    {
        [ZPath("@artist")]
        public string Artist { get; set; }
        [ZPath("@title")]
        public string Title { get; set; }
    }

    public class JukeboxPlaylist
    {
        [ZPath("entry")]
        public List<Child> Children { get; set; }
        [ZPath("@currentIndex")]
        public int CurrentIndex { get; set; }
        [ZPath("@Playing")]
        public bool Playing { get; set; }
        [ZPath("@gain")]
        public float Gain { get; set; }
    }

    [ZPath("chatMessage")]
    public class ChatMessages : List<ChatMessage>
    {
    }

    public class ChatMessage
    {
        [ZPath("@username")]
        public string username { get; set; }
        // TODO:  Formatter for DateTime
        [ZPath("@time")]
        public int Time { get; set; }
        [ZPath("@message")]
        public string Message { get; set; }
    }

    public class Directory
    {
        [ZPath("child")]
        public List<Child> Children { get; set; }
        [ZPath("@id")]
        public string Id { get; set; }
        [ZPath("@name")]
        public string Name { get; set; }
    }

    public class SearchResult
    {
        [ZPath("match")]
        public List<Child> Matches { get; set; }
        [ZPath("@offset")]
        public int Offset { get; set; }
        [ZPath("@totalHits")]
        public int TotalHits { get; set; }
    }

    [ZPath("playlist")]
    public class Playlists : List<PlaylistIdAndName>
    {
    }

    public class PlaylistIdAndName
    {
        [ZPath("@id")]
        public string Id { get; set; }
        [ZPath("@name")]
        public string Name { get; set; }
    }

    public class Playlist : PlaylistIdAndName
    {
        [ZPath("entry")]
        public List<Child> Entry { get; set; }
    }

    public class NowPlaying
    {
        [ZPath("entry")]
        public List<MusicFolder> Entries { get; set; }
    }

    public class NowPlayingEntry : Child
    {
        [ZPath("@username")]
        public string UserName { get; set; }
        [ZPath("@minutesAgo")]
        public int MinutesAgo { get; set; }
        [ZPath("@playerId")]
        public int PlayerId { get; set; }
        [ZPath("@playerName")]
        public string PlayerName { get; set; }
    }

    public class Child : ZPathObject
    {
        [ZPath("@id")]
        public string Id { get; set; }
        [ZPath("@isDir")]
        public bool IsDir { get; set; }
        [ZPath("@title")]
        public string Title { get; set; }
        [ZPath("@album")]
        public string Album { get; set; }
        [ZPath("@artist")]
        public string Artist { get; set; }
        [ZPath("@track")]
        public int Track { get; set; }
        [ZPath("@year")]
        public string Year { get; set; }
        [ZPath("@genre")]
        public string Genre { get; set; }
        [ZPath("@coverArt")]
        public string CoverArt { get; set; }
        [ZPath("@size")]
        public long Size { get; set; }
        [ZPath("@contentType")]
        public string ContentType { get; set; }
        [ZPath("@suffix")]
        public string Suffix { get; set; }
        [ZPath("@transcodedContentType")]
        public string TranscodedContentType { get; set; }
        [ZPath("@transcodedSuffix")]
        public string TranscodedSuffix { get; set; }
        [ZPath("@duration")]
        public int Duration { get; set; }
        [ZPath("@bitRate")]
        public int BitRate { get; set; }
        [ZPath("@path")]
        public string Path { get; set; }
    }
}